package com.example.ruteroelmeromero;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.OverlayItem;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.GridView;

public class DetalleVentas extends Activity {
	BaseDatos db = null;
	GridView gridView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_detalle_ventas);
		gridView = (GridView) findViewById(R.id.gridView1);
		if (db == null) {
			db = new BaseDatos(this);
		}
		List<Map> listado = db.listarTodo();
		String[] salida = new String[listado.size() * 4 + 4];		
		int cont = 0;
		salida[cont] = "prod";
		cont++;
		salida[cont] = "cant";
		cont++;
		salida[cont] = "precio";
		cont++;
		salida[cont] = "total";
		cont++;
		for (Map punto : listado) {
			salida[cont] = (String) punto.get("producto");
			cont++;
			salida[cont] = (String) punto.get("cantidad");
			cont++;
			salida[cont] = (String) punto.get("precio");
			cont++;
			salida[cont] = (String) punto.get("total");
			cont++;
		}
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, salida);
		gridView.setAdapter(adapter);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_detalle_ventas, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle item selection
		switch (item.getItemId()) {
		case R.id.menu_settings:
			Intent intent = new Intent(this, RuteroElMeroMero.class);
			this.startActivity(intent);
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}
}
